package jp.sourceforge.akjrcp.greycstoration;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import jp.sourceforge.akjrcp.util.PathnameUtils;


public class RestorationSetting {
private int mode;

private double alpha=0.6;
private double sigma=1.1;
private double p=0.9;
private double a=0.15;
private int dt=40;
private int iter=1;
private String exePath;
private Process process;
public RestorationSetting(String path){
	this.exePath=path;
}
public double getAlpha() {
	return alpha;
}
public void setAlpha(double alpha) {
	this.alpha = alpha;
}
public String getExePath() {
	return exePath;
}
public void setExePath(String exePath) {
	this.exePath = exePath;
}

public int getMode() {
	return mode;
}
public void setMode(int mode) {
	this.mode = mode;
}

public Process getProcess() {
	return process;
}
public void setProcess(Process process) {
	this.process = process;
}

public String toFileName(String name){
	String head=PathnameUtils.removeExtension(name);
	String exe=PathnameUtils.getExtension(name);
	String value="_";
	value+="alpha("+alpha+")_";
	value+="sigma("+sigma+")_";
	value+="p("+p+")_";
	value+="a("+a+")_";
	value+="iter("+iter+")_";
	value+="dt("+dt+")";
	
	return head+value+"."+exe;
}



public String[] toCommand(File input,File output) {
	List list=new ArrayList();
	list.add(exePath);
	list.add("-restore");
	list.add(input.getAbsolutePath());
	
	
	
	list.add("-alpha");
	list.add(""+alpha);
	
	list.add("-sigma");
	list.add(""+sigma);
	
	list.add("-p");
	list.add(""+p);
	
	list.add("-a");
	list.add(""+a);
	
	list.add("-iter");
	list.add(""+iter);
	
	list.add("-dt");
	list.add(""+dt);
	
	list.add("-o");
	list.add(output.getAbsolutePath());
	
	list.add("-visu");
	list.add("false");
	
	return (String[])list.toArray(new String[0]);
}
public int getIter() {
	return iter;
}
public void setIter(int iter) {
	this.iter = iter;
}
public double getA() {
	return a;
}
public void setA(double a) {
	this.a = a;
}
public int getDt() {
	return dt;
}
public void setDt(int dt) {
	this.dt = dt;
}
public double getP() {
	return p;
}
public void setP(double p) {
	this.p = p;
}
public double getSigma() {
	return sigma;
}
public void setSigma(double sigma) {
	this.sigma = sigma;
}

public void incrementValue(String paramName,double increment){
	if(paramName.equals("alpha")){
	alpha+=increment;
	BigDecimal bd = new BigDecimal(alpha);
	alpha=bd.setScale(1, BigDecimal.ROUND_HALF_UP)
    .doubleValue();
	}else if(paramName.equals("sigma")){
		sigma+=increment;
		BigDecimal bd = new BigDecimal(sigma);
		sigma=bd.setScale(1, BigDecimal.ROUND_HALF_UP)
	    .doubleValue();
	}else if(paramName.equals("p")){
		p+=increment;	
		BigDecimal bd = new BigDecimal(p);
		p=bd.setScale(1, BigDecimal.ROUND_HALF_UP)
	    .doubleValue();
	}else if(paramName.equals("a")){
		a+=increment;
		BigDecimal bd = new BigDecimal(a);
		a=bd.setScale(2, BigDecimal.ROUND_HALF_UP)
	    .doubleValue();
		a=Math.min(a, 1.0);//limit
	}else if(paramName.equals("iter")){
		iter+=increment;
	}else if(paramName.equals("dt")){
		dt+=increment;
	}
}

public String getParamLabel(String paramName){
	String label="-"+paramName;

	if(paramName.equals("alpha")){
		label+=" "+alpha;
	}else if(paramName.equals("sigma")){
		label+=" "+sigma;
	}else if(paramName.equals("p")){
		label+=" "+p;
	}else if(paramName.equals("a")){
		label+=" "+a;
	}else if(paramName.equals("iter")){
		label+=" "+iter;
	}else if(paramName.equals("dt")){
		label+=" "+dt;
	}
	return label;
}

}
